﻿Imports System.Xml

Public NotInheritable Class UsedExpressionVariable

    Public Sub New(ByVal _xVariable As XElement)
        __Name = _xVariable.<Name>.Value()
        __Type = _xVariable.<Type>.Value()
        __Value = _xVariable.<Value>.Value()
    End Sub

    Public Sub New(ByVal _expressionVariable As Enhancements.Basic.Expressions.ExpressionVariable)
        __Name = _expressionVariable.Name
        __Type = _expressionVariable.Type.Name
        __Value = _expressionVariable.Value
    End Sub

    Private __Name As String = Nothing
    Public ReadOnly Property Name As String
        Get
            Return __Name
        End Get
    End Property

    Private __Type As String = Nothing
    Public ReadOnly Property Type As String
        Get
            Return __Type
        End Get
    End Property

    Private __Value As Object = Nothing
    Public ReadOnly Property Value As Object
        Get
            Return __Value
        End Get
    End Property

    Public Function ToXElement() As XElement
        Dim _xElement As XElement = New XElement(XName.Get("Variable"))

        _xElement.Add(New XElement(XName.Get("Name"), Name))
        _xElement.Add(New XElement(XName.Get("Type"), Type))
        If Value Is Nothing Then
            _xElement.Add(New XElement(XName.Get("Value"), Nothing))
        Else
            _xElement.Add(New XElement(XName.Get("Value"), Value.ToString()))
        End If

        Return _xElement
    End Function

End Class
